﻿using NetTopologySuite.IO;
using NetTopologySuite.Operation.Distance;
using NUnit.Framework;

namespace NetTopologySuite.Samples.Tests.Github
{
    public class Issue444
    {
        [Test]
        public void Test()
        {
            var rdr = new WKTReader();
            var geom0 = rdr.Read(
@"LINESTRING(37.7224985654 -0.9555178485, 37.7226943974 -0.9554535447, 37.7229352226 -0.9553825995, 37.723181128 -0.955341998,
37.7234384814 -0.9552771203, 37.7237481242 -0.9552264134, 37.7241927331 -0.9551429879, 37.7247465157 -0.9550458111,
37.7252906081 -0.9549025103, 37.7260073939 -0.9547008659, 37.7266961443 -0.9544463063, 37.7271975705 -0.9542677211,
37.7275247714 -0.9541600877, 37.7278960455 -0.9540067672, 37.7279562199 -0.9545918853, 37.7280248243 -0.9553574602,
37.7281082916 -0.9560703664, 37.7281785921 -0.9567628655, 37.728241961 -0.9574851179, 37.7282899333 -0.9579211604,
37.728406797 -0.9591002592, 37.7285116219 -0.9600593024, 37.7286095979 -0.9609905579, 37.7286740215 -0.9616597345,
37.7287325308 -0.9622897772, 37.7288044601 -0.9630997691, 37.7288937412 -0.9643689763, 37.7290427091 -0.9657958785,
37.7291385693 -0.9669357838, 37.7292087963 -0.9677718666, 37.7293148069 -0.9689180115, 37.7293959591 -0.9697720861,
37.7294683595 -0.9706299638, 37.7295365948 -0.9707750019, 37.7300980277 -0.9706875215, 37.7312241207 -0.9704554138,
37.7322156915 -0.9702482864, 37.7329937243 -0.9700788735, 37.7336441253 -0.9699348312, 37.7345998334 -0.969702662, 
37.7354980229 -0.9695187068, 37.7362988481 -0.969273056, 37.7366833873 -0.9691528675, 37.7367509613 -0.9692824889,
37.7370790114 -0.9703683815, 37.7370889012 -0.9720775065, 37.737434433 -0.9727208544, 37.7377221441 -0.973204707,
37.7393064553 -0.9745088077, 37.7403573898 -0.9755188846, 37.7408684447 -0.97669274, 37.7414433551 -0.9779952721)");
            var geom1 = rdr.Read("POINT(37.7280838934 -0.9558619735)");

            var intersection = new DistanceOp(geom0, geom1).NearestPoints()[0];
            var testPoint = geom0.Factory.CreatePoint(intersection);

            double distance = geom0.Distance(testPoint);
            Assert.That(distance, Is.LessThan(1e10));

        }
    }
}
